-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NextJS Runtime middleware example #6
Conversation
Got it working by using |
|
WoW, nice! Thanks a lot! |
No problem. I forgot to mention that I had to use two separate variables for the frontend and backend. Here is my modified compose. services:
godoxy-frontend:
image: brandawg93/go-proxy-frontend:local
container_name: godoxy-frontend
restart: unless-stopped
env_file: .env
environment:
- GODOXY_API_ADDR=http://godoxy:8888
depends_on:
- godoxy
godoxy:
image: ghcr.io/yusing/go-proxy:latest
container_name: godoxy
restart: always
env_file: .env
environment:
- GODOXY_API_ADDR=0.0.0.0:8888 The image used for the frontend is just a local build I created. And I redacted other parts of my compose, but you get the gist. |
Oh, I expect, and GoDoxy currently only works in host network mode. So using the same value should be fine since the API expose sensitive info and should only be listening on 127.0.0.1. |
Using this I have it working in bridge mode. 😀 |
I got it working ac2b040: # godoxy/compose.yml
services:
frontend:
...
network_mode: host
env_file: .env
environment:
NEXT_PUBLIC_GODOXY_API_ADDR: ${GODOXY_API_ADDR}
... |
Nice! Do you need the NEXT_PUBLIC_ ? That would just make it available on the client side but you only need that variable in the middleware. |
Oh you're right. |
I hope this helps with the
GODOXY_API_ADDR
issue.The issue is that the configuration in
next.config.js
rewrites at compile time and not runtime. In order to be able to dynamically change the address, you would need to use middleware.This PR is an example of using the middleware to proxy the request to the api. I have deliberately left the debug logging in because I'm still having a connection refused issue. But I believe it may be an issue with my own personal setup. I'll continue to debug on my side, but I believe you may have a more comprehensive knowledge of the api portion. 😄
Let me know if you have any questions or if I can help further!